\documentclass[border=10pt,tikz]{standalone}
\usepackage{pgfplots,pgfplotstable,tikz}
\usetikzlibrary{intersections}
\usepackage{verbatim}
\usepackage{moresize}
\usetikzlibrary{calc}
\usepackage{datatool}
\usepackage{csvsimple}
\usepackage{siunitx}
\usepackage{xspace} 
\usepgfplotslibrary{fillbetween}
\usepackage{etoolbox}
\usepackage{multirow}
\usetikzlibrary{arrows.meta}
\usetikzlibrary{positioning}
\usetikzlibrary{decorations.text} 
\usetikzlibrary{decorations.pathmorphing}
\pgfplotsset{compat=1.13}
\usepackage{fp}


\definecolor{green}{RGB}{68,126,35}
\definecolor{blue}{RGB}{19,30,92}
\definecolor{red}{RGB}{219,51,24}

% efines "sgn" function
\def\sgn{\mathop{\rm sgn}\nolimits} 
% Defines the expectation function
\def\E{\mathop{\mathrm{E}}\nolimits} 

% Defines a function that ignores the zero on the y- or the x-axis, such that the origin
% is only labeled once. Activate in the axis options by adding the key: "ignore zero=x" or ""ignore zero=y."
\pgfplotsset{ignore zero/.style={%
		#1ticklabel={\ifdim\tick pt=0pt \else\pgfmathprintnumber{\tick}\fi}
	}}
	
	
	
	\begin{document}
		% This figure is plotted directly using Figure 8 from Hackmann et al. (2015). 		
			
			\pgfmathsetmacro\pB{0.7}
			\pgfmathsetmacro\pI{0.97}
			\pgfmathsetmacro\logp{-0.86296296296}
			
			% [yaxismin, yaxismax, yaxislength] Calculate graphing region for the y-axis
			\pgfmathsetmacro\pBdi{round(1000*\pB)/1000}
			\pgfmathsetmacro\pIdi{round(1000*\pI)/1000}
			
		
			% MTE(pC) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
			\begin{tikzpicture}[>=stealth]
			% Axis options
			\begin{axis}[					
			width=15cm,					% width of chart
			height=10cm,				% height of chart
			xlabel={$U_D$:  unobserved net cost of treatment \\ \textcolor{gray!90}{$I$: fraction insured}},				% x-axis title
			ylabel={log premium},					% y-axis title
			ylabel style={rotate=-90, at=(current axis.above origin), anchor=south east},  % rotate the y-axis title
			samples=100,  				% sets the resolution for curved lines
			xmin=0,xmax=1,			    % x-axis range
			ymin=8,ymax=9.05,
			ignore zero=y,			    % ignore the zero on the y-axis (defined in preamble)
			xtick={0,1},	    % only show these x ticks
			xticklabels={0,1},% label x ticks
			ytick={8.4,8.5,8.6,8.7,9},
			yticklabels={$\textcolor{gray!90}{P^{*,\,post}=} \,8.4$,$\textcolor{gray!90}{AC^{*,\,post}=} \,8.5$,$\textcolor{gray!90}{AC^{*,\,pre}=\, }8.6$,$\textcolor{gray!90}{P^{*,\,pre}= }\,8.7$,9},
			legend style={draw=none,legend pos=north west},	% set legend style, specifically no outline
			legend cell align={left},	% align legend content to the left
			clip=false,					% place nodes outside of plot area
			xticklabel style={
						align=center,
						yshift=-5.5ex,
						name=label,
						append after command={(label.north) edge [solid] ++(0,6ex)},
										/pgf/number format/fixed,
										/pgf/number format/precision=2},
					x label style={at={(axis description cs:0.5,-0.2)},anchor=north}, % ncrease distance between title and x-axis
					yticklabel style={/pgf/number format/fixed},
					% place some extra y ticks ...
					extra y ticks={0},
					% ... but do not repeat the already existent labels
					% (from the "normal" ticks) ...
					extra y tick labels={0},
					% ... and set the style of the extra ticks to `major'
					extra tick style={
						grid=major,
					},
			xlabel style={align=center,xshift=0pt,yshift=-20pt},
			 mydot/.style={
			 	circle,
			 	fill=white,
			 	draw,
			 	outer sep=0pt,
			 	inner sep=1.5pt
			 },
			restrict y to domain=8:9.05,
			]			
			
			%mte(p)
			\addplot[domain=0:1, line width=1pt, gray!90, opacity=1, name path =AC]
				{8.85925925926+(-0.37037037037)*\x}
				node[pos=0.25,pin={[pin edge=white,pin distance=-9pt]45:{$AC\left(I\right)$}}] {};
			\addplot[domain=0:0.7,line width=1pt, gray!90, dashed, opacity=1]
							{8.6};
			\addplot[domain=0:0.7,line width=1pt, gray!90, dashed, opacity=1]
							{8.7};
			\addplot[domain=0:0.97,line width=1pt, gray!90, dashed, opacity=1]
										{8.4};
			\draw [line width=1pt,dashed,gray!90] (0.7,8) -- (0.7,8.7);
			\draw [line width=1pt,dashed,gray!90] (0.97,8) -- (0.97,8.5);
			\addplot[domain=0:0.97, line width=1pt,gray!90, dashed, opacity=1]
										{8.5};
			\addplot[domain=0:1, line width=1.8pt, red, opacity=1, name path=MC]
							{8.85925925926+2*(-0.3703703)*\x};
			
	
			
			\addplot[mark=*,gray!90] coordinates {(0.97,8.4)};
			\node[mark=*,label={[label distance=-3pt]188:{\color{gray!90}{A$'$}}}] at (axis cs:0.97,8.4) {};
			
			\addplot[mark=*,gray!90] coordinates {(0.7,8.34074083926)};
			\addplot[mark=*,gray!90] coordinates {(0.97,8.14074087726)};
			\node[mark=*,label={[label distance=-4pt]200:{\color{gray!90}{D}}}] at (axis cs:0.7,8.34074083926) {};
			\node[mark=*,label={[label distance=-4pt]200:{\color{gray!90}{D}$'$}}] at (axis cs:0.97,8.14074087726) {};
	 
			\addplot[mark=*,gray!90] coordinates {(0.7,8.7)};
			\node[mark=*,label={[label distance=-5pt]75:{\color{gray!90}{A}}}] at (axis cs:0.7,8.7) {};
			
			
	
			\addplot[domain=0:1, line width=1pt, gray!90, opacity=1, name path=D]
				{10.1+(-2)*\x}
				node[pos=0.188,pin={[pin edge=white,pin distance=-9pt]45:{$D\left(I,0\right)$}}] {};
				
			\addplot[domain=0:1, line width=1pt, gray!90, opacity=1, name path=Dpi]
				{10.34+(-2)*\x}
				node[pos=0.25,pin={[pin edge=white,pin distance=-9pt]45:{$D\left(I,\pi\right)$}}] {};
	
			\node (source) at (axis cs:1.02,8.08){};
			\node (destination) at (axis cs:1.02,8.35){};
			\draw[->,line width=0.9pt,color=gray!90](source)--(destination)
				node[pos=0.5,pin={[fill=white,pin edge=white,pin distance=-3pt]60:{$\pi=0.24$}}] {};
	
			\addplot[gray!10] fill between[of=D and MC,soft clip={domain=0.7:0.97}];
	
			% add legend
			\legend{,,,,,{Massachusetts $\text{MTE}\left(p\right)$, $\textcolor{gray}{MC(I)}$}}

			% Put Always Takers, Compliers, and Never Takers on the x-axis
			\draw[draw=none,decorate,decoration={brace,amplitude=10pt,mirror,raise=4pt},yshift=0pt] (0,8) -- (\pB, 8) node[pos=0.5, below, yshift = 0pt, align=left] {Always Takers};
			\draw[draw=none,decorate,decoration={brace,amplitude=10pt,mirror,raise=4pt},yshift=0pt] (\pB,8) -- (\pI, 8) node[pos=0.5, below, yshift = 0pt] {Compliers};
			%\draw[draw=none,decorate,decoration={brace,amplitude=10pt,mirror,raise=4pt},yshift=0pt] (\pI,8) -- (1, 8) node[pos=0.5, below, yshift = 0pt, align=left] {Never \\ Takers};
			
\draw[decorate,decoration={brace,amplitude=3.5pt,mirror,raise=2pt},yshift=0pt] (0.97,8) -- (1, 8);
			
			\node[label={[align=left]0:{Never \\ Takers}},circle,fill,inner sep=2pt,opacity=0] at (axis cs:1.045,7.943) {};
			\draw [thin,black] (0.985,8-0.025) -- (1.05,7.943);
			
			\node[label={[align=center]-90:{$p_C=0.70$\\ \color{gray!90}$I^{*,\,pre}$}},circle,fill,inner sep=2pt,opacity=0] at (axis cs:0.7,7.84) {};
			\draw [thin,black] (0.7,7.84) -- (0.7,8);
			
			\node[label={[align=center]-90:{$p_I=0.97$\\ \color{gray!90}$I^{*,\,post}$}},circle,fill,inner sep=2pt,opacity=0] at (axis cs:0.97,7.84) {};
			\draw [thin,black] (0.97,7.84) -- (0.97,8);
				

			\end{axis}
			
		
			\end{tikzpicture}
		
		
		
	\end{document}
